//
//  WSCommentCell.m
//  WisdomStar
//
//  Created by 谭飞 on 2018/10/31.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "WSCommentCell.h"
#import "WSReplyTableCell.h"

#import "WSMessageInfo.h"

@interface WSCommentCell ()<UITableViewDataSource, UITableViewDelegate>
// 回复列表
@property (weak, nonatomic) IBOutlet UITableView *replyTable;
// 评论内容
@property (weak, nonatomic) IBOutlet UILabel *replyContentLab;
// 评论时间
@property (weak, nonatomic) IBOutlet UILabel *timeLab;
// 点赞次数
@property (weak, nonatomic) IBOutlet UILabel *likeCountLab;
// 用户名
@property (weak, nonatomic) IBOutlet UILabel *nameLab;
// 用户头像
@property (weak, nonatomic) IBOutlet UIImageView *headImgView;
// 点赞按钮
@property (weak, nonatomic) IBOutlet UIButton *likeBtn;


@end

@implementation WSCommentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self.headImgView setCorners:UIRectCornerAllCorners cornerRadius:self.headImgView.xmg_height];
    
//    [self.replyTable registerNib:[UINib nibWithNibName:[WSReplyTableCell className] bundle:nil] forCellReuseIdentifier:[WSReplyTableCell className]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

// 计算内容高度
- (CGFloat)contentHeight {
    return 60.f + self.replyContentLab.xmg_bottom + 10.f;
}


- (IBAction)likeBtnClick:(UIButton *)sender {
    if (sender.isSelected) return;
    if (self.didTapLikeCallback) {
        self.didTapLikeCallback(sender, self);
    }
}


#pragma mark - UITableViewDataSource, UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WSReplyTableCell *cell = [tableView dequeueReusableCellWithIdentifier:[WSReplyTableCell className] forIndexPath:indexPath];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 30.f;
}

#pragma mark - Setter

- (void)setMessageInfo:(WSMessageInfo *)messageInfo {
    _messageInfo = messageInfo;
    [self.headImgView sd_setImageWithURL:[NSURL URLWithString:messageInfo.head]];
    self.likeBtn.selected = messageInfo.zan > 0;
    self.nameLab.text = messageInfo.uname;
    self.timeLab.text = messageInfo.create_at;
    self.likeCountLab.hidden = messageInfo.zan == 0;
    self.likeCountLab.text = [NSString stringWithFormat:@"%ld",(long)messageInfo.zan];
    self.replyContentLab.text = messageInfo.msg;
}


@end
